package com.malty.sentinel.aop;

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * @author malty
 */
@Component
@Aspect
public class SentinelAop {

    @Around("execution(* com.malty.sentinel.controller..*.*(..))")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        Signature signature = point.getSignature();
        Object proceed = null;
        try (Entry entry = SphU.entry("测试")) {
            proceed = point.proceed();
        } catch (BlockException e) {
            System.out.println("限流执行");
            throw new RuntimeException(e.getMessage());
        }
        return proceed;
    }

}
